<?php
namespace app\admin\model;

use think\Db;
use think\Model;

/**
 * 预警
 * @package app\admin\model
 */
class WarConfig extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'war_config';

    public function getList($request)
    {
        $war_config = $this
            ->alias('war')
            ->field('war.*,cha.company_name')
            ->join('bus_channel cha', 'cha.channel_id = war.sms_cid', 'LEFT')
            ->paginate($request['limit'], false, ['query' => $request])
            ->each(function ($item, $key) {

                switch ($item->code) {
                    case 'CC':
                        $item->sms_plat = '<a href="javascript:;" style="color:blue" onClick="openWarChannel(' . $item->id . ')"> 查看(' . Db::table('war_channel_change')->where('war_id', $item->id)->count() . ') </a>';
                        break;
                    case 'CU':
                        $item->sms_plat = '<a href="javascript:;" style="color:blue" onClick="openWarUrl(' . $item->id . ')"> 查看(' . Db::table('war_check_url')->where('war_id', $item->id)->count() . ') </a>';
                        break;
                    default:
                        $item->sms_plat = '<a href="javascript:;" style="color:blue" onClick="openUser(' . $item->id . ')"> 查看(' . Db::table('war_user')->where('war_id', $item->id)->count() . ') </a>';
                        break;
                }

                switch ($item->code) {
                    case 'F':
                        $item->code = '失败';
                        break;
                    case 'W':
                        $item->code = '待处理';
                        break;
                    case 'CB':
                        $item->code = '渠道余额不足';
                        break;

                    default:
                        # code...
                        break;
                }
                switch ($item->sms_onoff) {
                    case '0':
                        $item->sms_onoff_ = '<span class="layui-badge layui-bg-orange">已禁用</span>';
                        break;
                    case '1':
                        $item->sms_onoff_ = '<span class="layui-badge layui-bg-green">已开启</span>';
                        break;

                    default:
                        $item->sms_onoff_ = '';
                        break;
                }
                switch ($item->onoff) {
                    case '0':
                        $item->onoff_ = '<span class="layui-badge layui-bg-orange">已禁用</span>';
                        break;
                    case '1':
                        $item->onoff_ = '<span class="layui-badge layui-bg-green">已开启</span>';
                        break;

                    default:
                        $item->onoff_ = '';
                        break;
                }

            });

        return $war_config->toarray();
    }
}
